<script setup lang="ts">
import ForumItme from './forum.vue'
import { getPostListAPI } from '@/api/posts'
import { PageProps } from '@/hooks/usePage'
import Comment from '@/components/forumList/comment.vue'

const MeScrollPageREF = ref()
const commentREF = ref()
const shareComREF = ref()
const emit = defineEmits(['shareObj'])
const props = defineProps({
    data: {
        type: Array,
        default: () => []
    },
    createdIsNeed: {
        type: Boolean,
        default: true
    }
})

// 显示评论
const showComment = (row: any) => {
    commentREF.value.showComment(row.id)
}

const reGetList = (row?: any) => {
    // page.fetchData = getPostListAPI;
}

onLoad(() => {
    // uni.$on('commentPost', (item: any) => {
    //     console.log('点击了评论', item)
    //     showComment(item)
    // })
    // if (props.createdIsNeed) {
    //   reGetList();
    // }
})
onUnload(() => {
    uni.$off('commentPost')
})

const showPreview = ref(false)
const imgCurrunt = ref(0)
const preViewImgList = ref<string[]>([])
const setPreview = (index: number, urls: string[]) => {
    console.log('展示')
    imgCurrunt.value = index
    preViewImgList.value = urls
    showPreview.value = true
}

// 分享
const showShare = (item: any) => {
    console.log('分享内容', item)
    shareComREF.value.shareFn(item)
    emit('shareObj', item)
}

defineExpose({
    setPreview,
    MeScrollPageREF,
    reGetList
})
</script>

<template>
    <view>
        <template v-for="(item, index) in props.data" :key="index">
            <ForumItme
                @commentPost="showComment"
                @showShare="showShare"
                @showImg="setPreview"
                :item="item"
            ></ForumItme>
        </template>
    </view>
    <!--    <fui-gallery-->
    <!--        :urls="preViewImgList"-->
    <!--        :current="imgCurrunt"-->
    <!--        :show="showPreview"-->
    <!--        @hide="showPreview = false"-->
    <!--    ></fui-gallery>-->
    <shareCom ref="shareComREF"></shareCom>
    <Comment ref="commentREF"></Comment>
</template>

<style scoped lang="scss"></style>
